import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:full_display/common/qxp_color.dart';

showToast(String msg, {Color? bgColor, bool? toastLength}) async {
  await Fluttertoast.cancel(); //防止toast频繁触发
  Fluttertoast.showToast(
      msg: msg,
      gravity: ToastGravity.CENTER,
      textColor: ColorPlate.white,
      fontSize: 16,
      toastLength: toastLength == true ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT,
      backgroundColor: bgColor ?? ColorPlate.black);
}

showLoading(context, [String? text]) {
  text = text ?? "Loading...";
  showDialog(
      barrierDismissible: false,
      context: context,
      builder: (context) {
        return Center(
          child: Container(
            decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.circular(3.0),
                boxShadow: [
                  //阴影
                  BoxShadow(
                    color: Colors.black12,
                    //offset: Offset(2.0,2.0),
                    blurRadius: 10.0,
                  )
                ]),
            padding: EdgeInsets.all(16),
            margin: EdgeInsets.all(16),
            constraints: BoxConstraints(minHeight: 120, minWidth: 180),
            child: Column(
              mainAxisSize: MainAxisSize.min,
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                SizedBox(
                  height: 30,
                  width: 30,
                  child: CircularProgressIndicator(
                    strokeWidth: 3,
                  ),
                ),
                Padding(
                  padding: const EdgeInsets.only(top: 20.0),
                  child: Text(
                    text ?? '',
                  ),
                ),
              ],
            ),
          ),
        );
      });
}
